package com.yanghui.lingyue.functions.defaultFunction

import com.icedata.sika.bridge.SikaEvent
import com.icedata.sika.bridge.SikaUserEvent
import com.icedata.sika.core.CommandProcessor
import com.icedata.sika.core.Sika
import com.icedata.sika.util.Logger
import com.yanghui.lingyue.bot.Bot
import com.yanghui.lingyue.data.Command
import com.yanghui.lingyue.data.User
import java.util.*

object NewUserFunction {
    val name: String = "NewUser"

    suspend fun parse(event: SikaEvent, sika: Sika): LinkedList<Command> {
        val command = LinkedList<Command>()
        if (event is SikaUserEvent)
            return command
        if (event.sender.id !in Bot.userList.keys) {
            command.add(Command(event, "ADD NewUser", ""))
        }
        return command
    }

    suspend fun execute(command: Command, sika: Sika): CommandProcessor.Result {
        Bot.userList[command.sender.id] = User(command)
        Logger.logDebug("AddUser", "Nick: ${command.sender.name}, Group: ${command.sender.groupName}")
        return CommandProcessor.Result.ADOPT
    }

    fun filter(command: Command): Boolean {
        if (command.instruction == "ADD NewUser")
            return true
        return false
    }

}